package com.platform.corejwt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;

/**
 * redis配置文件
 * @author rainly
 */
@Configuration
@EnableTransactionManagement
public class RedisTxContextConfiguration {

    /**载入配置文件配置的连接工厂**/
    @Resource
    RedisConnectionFactory redisConnectionFactory;

    @Bean
    public StringRedisTemplate redisTemplate(){
        StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(redisConnectionFactory);
        //显式启用事务支持
        stringRedisTemplate.setEnableTransactionSupport(true);
        return stringRedisTemplate;
    }
}
